//@author A0096723X
///@class EntriesSorter
///@Description This class is the helper function library of the executor of BOT program.
///				EntriesSorter handles the following operations
///				1. Handles filter operations, to sort to past, today, tomorrow, future events
///				2. Handles splitting functions that takes in a vector<Entry*> and splits them into two according to search criteria.
///				3. Sorts the vector<Entry*> according to pre-defined sorting requirements.
///				4. getCount returns the number of different types of entries, overdue, today, tasks, events.
#ifndef ENTRIESSORTER_H
#define ENTRIESSORTER_H
#include<string>
#include<vector>
#include<stack>
#include <sstream>
#include <algorithm>

#include <exception>
#include <assert.h>

#include <libqxt-Qt5\include\QxtCore\qxtloggerengine.h>
#include <libqxt-Qt5\include\QxtCore\qxtlogger.h>
#include <libqxt-Qt5\include\QxtCore\QxtLogger>
#include <libqxt-Qt5\include\QxtCore\QxtBasicFileLoggerEngine>
#include <libqxt-Qt5\include\QxtCore\QxtBasicSTDLoggerEngine>

#include "Entry.h"
#include "CommonEnum.h"
#include "CommonUtils.h"
#include "FileManager.h"
#include "BotException.h"

using namespace std;
class EntriesSorter
{
	static bool isFound(string target, Entry* entry);

	static void assignFoundNotFound(string target, vector<Entry*>& found, vector<Entry*>& notFound);
	static void assignFoundNotFoundExact(string target, const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound);

	static void countOverdueTodayFuture(CommonEnum::ReturnCount& entriesCount, Entry* entry);
	static void countEventTask(CommonEnum::ReturnCount& entriesCount, Entry* entry);
public:
	EntriesSorter(void);
	~EntriesSorter(void);

	//@brief seperates the entries vector according to past, today, tomorrow, future, sorts them individually and combine them together
	static void defaultSort(vector<Entry*>& entries);

	//@brief sorts the entries vector according to date as one single vector
	static void sortByDate(vector<Entry*>& entries);

	static bool isTask(Entry* entry);
	static bool isPast(Entry* entry);
	static bool isToday(Entry* entry);
	static bool isTomorrow(Entry* entry);

	//@brief splits the vector according to the specified filter.
	//@param string/QDate/bool parameters are taken in as search criteria.
	static void splitVector(string target, const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound, CommonEnum::SEARCH_TYPE);
	static void splitVectorTask(const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound);
	static void splitVectorEvent(const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound);
	static void splitVectorDay(QDate target,const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound, CommonEnum::SEARCH_TYPE);
	static void splitVectorDay(QDate target,const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound);
	static void splitVectorStatus(bool target, const vector<Entry*>& entries, vector<Entry*>& found, vector<Entry*>& notFound);

	//@brief counts the different types of entries in the vector taken in.
	static CommonEnum::ReturnCount getCount(vector<Entry*>& entries);
};

#endif